<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: router.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

/*
 * Function to convert a system URL to a SEF URL
 */
function JhtraqBuildRoute(&$query) {
   
   $segments = array();
   
   if(!isset($query['view']))
		return array();
   
   
   $segments[] = $query['project'];
   $segments[] = $query['view'];
   unset($query['project']);
   switch($query['view'])
   {
	   case 'projects':
			$segments[1] = 'information';
		   break;
	   case 'wiki':
		   if(isset($query['page']))
		   {
				$segments[] = $query['page'];
				unset($query['page']);
				if(isset($query['task']))
				{
					$segments[] = $query['task'];
					unset($query['task']);
				}
		   }
	   break;
	   case 'tickets':
		   if(isset($query['layout']))
		   {
			   $segments[] = $query['layout'];
			   unset($query['layout']);
			   if(isset($query['ticket']))
			   {
				   $segments[] = $query['ticket'];
				   unset($query['ticket']);
			   }
		   }
		   break;
	   case 'releases':
		   if(isset($query['task']))
		   {
			   $segments[] = $query['task'];
			   unset($query['task']);
			   if(isset($query['download']))
			   {
				   $segments[] = $query['download'];
				   unset($query['download']);
			   }
		   }
		   break;
	   case "svn":
		   if(isset($query['action']))
		   {
			   $segments[] = $query['action'];
			   unset($query['action']);
		   }
		   break;
   }
   
   unset($query['view']);
   return $segments;
}
/*
 * Function to convert a SEF URL back to a system URL
 */
function JhtraqParseRoute($segments) {
	$query = array();
	
	if(isset($segments[0]))
	{
		$v = $segments[1];
		$query['project'] = $segments[0];
		$query['view'] = $segments[1];
		switch($v)
		{
			case 'information':
					$query['view'] = 'projects';
				break;
			case 'wiki':
				if(isset($segments[2]))
				{
					$query['page'] = $segments[2];
					if(isset($segments[3]))
					{
						$query['task'] = $segments[3];
					}
				}
				break;
			case 'tickets':
				if(isset($segments[2]))
				{
					$query['layout'] = $segments[2];
					if(isset($segments[3]))
					{
						$query['ticket'] = $segments[3];
					}
				}
				break;
			case 'releases':
				if(isset($segments[2]))
				{
					$query['task'] = $segments[2];
					if(isset($segments[3]))
					{
						$query['download'] = $segments[3];
					}
				}
				break;
			case "svn":
				if(isset($segments[2]))
				{
					$query['action'] = $segments[2];
				}
				break;
		}
		
	}
	
	return $query;
	
}
?>